/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export const airBlob = '/*\n * Copyright (C) 2016-2017 Apple Inc. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS\'\' AND ANY\n * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR\n * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\n * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY\n * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \n */\n\"use strict\";\n\nclass Reg extends TmpBase {\n    constructor(index, type, name, isCalleeSave)\n    {\n        super();\n        this._index = index;\n        this._type = type;\n        this._name = name;\n        this._isCalleeSave = !!isCalleeSave;\n    }\n    \n    static fromReg(reg)\n    {\n        return reg;\n    }\n    \n    get index() { return this._index; }\n    get type() { return this._type; }\n    get name() { return this._name; }\n    get isCalleeSave() { return this._isCalleeSave; }\n    \n    get isReg() { return true; }\n    \n    hash()\n    {\n        if (this.isGP)\n            return 1 + this._index;\n        return -1 - this._index;\n    }\n    \n    toString()\n    {\n        return `%${this._name}`;\n    }\n    \n    static extract(arg)\n    {\n        if (arg.isReg)\n            return arg.reg;\n        return null;\n    }\n    \n    static forEachFast(arg, func)\n    {\n        return arg.forEachTmpFast(tmp => {\n            if (!tmp.isReg)\n                return;\n            return func(tmp);\n        });\n    }\n    \n    static forEach(arg, argRole, argType, argWidth, func)\n    {\n        return arg.forEachTmp(\n            argRole, argType, argWidth,\n            (tmp, role, type, width) => {\n                if (!tmp.isReg)\n                    return;\n                return func(tmp, role, type, width);\n            });\n    }\n}\n\n{\n    Reg.regs = [];\n    function newReg(...args)\n    {\n        let result = new Reg(...args);\n        Reg.regs.push(result);\n        return result;\n    }\n\n    // Define X86_64 GPRs\n    {\n        let index = 0;\n        function newGPR(name, isCalleeSave) { return newReg(index++, GP, name, isCalleeSave); }\n        \n        Reg.rax = newGPR(\"rax\");\n        Reg.rcx = newGPR(\"rcx\");\n        Reg.rdx = newGPR(\"rdx\");\n        Reg.rbx = newGPR(\"rbx\", true);\n        Reg.rsp = newGPR(\"rsp\");\n        Reg.rbp = newGPR(\"rbp\", true);\n        Reg.rsi = newGPR(\"rsi\");\n        Reg.rdi = newGPR(\"rdi\");\n        for (let i = 8; i <= 15; ++i)\n            Reg[`r${i}`] = newGPR(`r${i}`, i >= 12);\n    }\n\n    // Define X86_64 FPRs.\n    for (let i = 0; i <= 15; ++i)\n        Reg[`xmm${i}`] = newReg(i, FP, `xmm${i}`);\n\n    Reg.gprs = []\n    Reg.fprs = []\n    Reg.calleeSaveGPRs = []\n    Reg.calleeSaveFPRs = []\n    Reg.calleeSaves = []\n    for (let reg of Reg.regs) {\n        if (reg.isGP) {\n            Reg.gprs.push(reg);\n            if (reg.isCalleeSave)\n                Reg.calleeSaveGPRs.push(reg);\n        } else {\n            Reg.fprs.push(reg);\n            if (reg.isCalleeSave)\n                Reg.calleeSaveFPRS.push(reg);\n        }\n        if (reg.isCalleeSave)\n            Reg.calleeSaves.push(reg);\n    }\n    \n    Reg.callFrameRegister = Reg.rbp;\n    Reg.stackPointerRegister = Reg.rsp;\n}\n';